package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strings"
)

type Producer struct {
	closedChan chan struct{}
}

func (producer *Producer) Produce(filename string, ch chan<- *sourceData) {

	fmt.Println("in Produce begin")
	f, err := os.Open(filename)
	if err != nil {
		panic(err)
	}
	defer f.Close()

	rd := bufio.NewReader(f)
	count := 0
	for {
		line, _, err := rd.ReadLine() //以'\n'为结束符读入一行

		if err == io.EOF {
			break
		}

		if err != nil {
			break
		}

		str := string(line)
		if str == "" || len(str) < 10 {
			continue
		}

		kk := strings.Split(str, ",")

		count++
		ch <- &sourceData{kk[0], kk[1], kk[2]}
	}
	fmt.Println("in Produce  over")
	close(producer.closedChan)
}
